<template>
  <p-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">

            <p-form layout="inline" @keyup.enter.native="searchQuery">
              <p-row :gutter="24">
                <!-- 条码扫描  -->
                <p-col :xl="6" :lg="7" :md="8" :sm="24">
                  <p-form-item label="条码扫描：">
                    <p-input placeholder="" style="width: 200px" />
                  </p-form-item>
                </p-col>
                 <!-- 线体下拉输入框 -->
                  <p-col :xl="6" :lg="7" :md="8" :sm="24">
                    <p-form-item label="线体">
                      <j-dict-select-tag placeholder="请选择" v-model="queryParam.filedType" dictCode="mes_filed_type"/>
                    </p-form-item>
                </p-col>
                 <!-- 工站下拉输入框 -->
                <p-col :xl="6" :lg="7" :md="8" :sm="24">
                    <p-form-item label="工站">
                      <j-dict-select-tag placeholder="请选择" v-model="queryParam.filedType" dictCode="mes_filed_type"/>
                    </p-form-item>
                </p-col>
              </p-row>
            </p-form>
                  <!-- 按钮区域 -->
                  <div>
                    <!-- 超领物料 -->
                    <p-button class="BtMargin" @click="handleAdd" type="primary">超领物料</p-button>
                    <!-- 生产退料 -->
                    <p-button class="BtMargin" @click="handleAdd" type="primary">生产退料</p-button>
                     <span class="print">是否在线打印<p-switch class="switch" checked-children="开" un-checked-children="关" default-checked /></span>
                  </div>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 左右布局 -->
    <div class="container">
      <div class="left">
        <div class="left_container_laber">
            <div class="text_1">工序工单列表</div>
            <div class="text_2">刷新</div>
        </div>
        <div class="left_container_info">
          <div>
            <div>500002912</div>
            <div>融合天线V2</div>
          </div>
          <div>
            <div>1000PCS</div>
            <div>2019-03-31</div>
          </div>
          <div>
             <p-button type="primary">开工</p-button>
          </div>
        </div>
      </div>
        <div class="right">
          <!-- 右侧Table区域 -->
          <div class="rightContainer_top">
              <div class="container_1">
                      <div class="container1_2">
                        <div class="container1_2_1">SOP</div>
                        <div class="container1_2_2"><p-button type="link">查看</p-button></div>
                      </div> 
                      <div class="container1_2_3">产品名称：</div>
                      <div class="container1_2_4">SOP名称：</div>
                      <div class="container1_2_5">版本号：</div>
              </div>
              <div class="container_2">
                      <div class="container1_2">
                        <div class="container1_2_1">SOP</div>
                        <div class="container1_2_2"><p-button type="link">查看</p-button></div>
                      </div> 
                      <div class="container1_2_3">产品名称：</div>
                      <div class="container1_2_4">SOP名称：</div>
                      <div class="container1_2_5">版本号：</div>
              </div>
              <div class="container_3">
                       <div class="container1_2">
                        <div class="container1_2_1">SOP</div>
                        <div class="container1_2_2"><p-button type="link">查看</p-button></div>
                      </div> 
                      <div class="container1_2_3">产品名称：</div>
                      <div class="container1_2_4">SOP名称：</div>
                      <div class="container1_2_5">版本号：</div>
              </div>
          </div>
          <div class="rightContainer_bottom">
              <div class="container_1">
                      <div class="container1_2">
                        <div class="container1_2_1">SOP</div>
                        <div class="container1_2_2"><p-button type="link">查看</p-button></div>
                      </div> 
                      <div class="container1_2_3">产品名称：</div>
                      <div class="container1_2_4">SOP名称：</div>
                      <div class="container1_2_5">版本号：</div>
              </div>
              <div class="container_2">
                      <div class="container1_2">
                        <div class="container1_2_1">SOP</div>
                        <div class="container1_2_2"><p-button type="link">查看</p-button></div>
                      </div> 
                      <div class="container1_2_3">产品名称：</div>
                      <div class="container1_2_4">SOP名称：</div>
                      <div class="container1_2_5">版本号：</div>
              </div>
              <div class="container_3">
                       <div class="container1_2">
                        <div class="container1_2_1">SOP</div>
                        <div class="container1_2_2"><p-button type="link">查看</p-button></div>
                      </div> 
                      <div class="container1_2_3">产品名称：</div>
                      <div class="container1_2_4">SOP名称：</div>
                      <div class="container1_2_5">版本号：</div>
              </div>
          </div>
             <div class="setPage">
                  <p-pagination v-model="ipagination.current" :total="50" show-less-items />
            </div>
    </div>
  </div>
  </p-card>
</template>

<script>
//1.引入JDictSelectTag组件
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue' 

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {api} from '@/api/manage'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import { filterObj } from '@/utils/util';
  import MesMfProcessModal from './modules/MesMfProcessModal'

  import Vue from 'vue'
  import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
  import ButtonExpHandler from '@/components/jeecgbiz/modules/ButtonExpHandler'
  import { postAction,getAction,deleteAction } from '@/api/manage'
  import FxCompontensModal from "@/components/jeecgbiz/FxCompontensModal"



  //高级查询modal需要参数
  const superQueryFieldList=[
          {
              value:'productType',
              text: '产品类型',
              type: 'string'
          },
          {
              value:'productCategory',
              text: '产品类别',
              type: 'string'
          },
          {
              value:'processType',
              text: '工单类型',
              type: 'select',
              dictCode: 'mes_process_type'
          },
          {
              value:'taskSource',
              text: '任务来源',
              type: 'string'
          },
          {
              value:'selfControl',
              text: '自制/外协',
              type: 'string'
          },
          {
              value:'productionno',
              text: '工单号',
              type: 'string'
          },
          {
              value:'processbillno',
              text: '工序工单号',
              type: 'string'
          },
          {
              value:'processTwocode',
              text: '二级工序编码',
              type: 'string'
          },
          {
              value:'processTwoname',
              text: '二级工序名称',
              type: 'string'
          },
          {
              value:'lineno',
              text: '线体编码',
              type: 'string'
          },
          {
              value:'linename',
              text: '线体名称',
              type: 'string'
          },
          {
              value:'mcode',
              text: '物料编码',
              type: 'String'
          },
          {
              value:'mname',
              text: '物料名称',
              type: 'String'
          },
          {
              value:'bomversions',
              text: 'BOM版本',
              type: 'string'
          },
          {
              value:'billnoStatus',
              text: '工单状态',
              type: 'select',
              dictCode: 'mes_billno_status'
          },
          {
              value:'starttime',
              text: '计划开始时间',
              type: 'Date'
          },
          {
              value:'completiontime',
              text: '计划完成时间',
              type: 'Date'
          },
          {
              value:'qistate',
              text: '物料齐套状态',
              type: 'select',
              dictCode: 'mes_qistate'
          },
          {
              value:'planQty',
              text: '计划数量',
              type: 'string'
          },
          {
              value:'schedule',
              text: '完成进度',
              type: 'string'
          },
          {
              value:'bomstatus',
              text: 'BOM状态',
              type: 'int'
          },
          {
              value:'createBy',
              text: '创建人',
              type: 'string'
          },
          {
              value:'createTime',
              text: '创建日期',
              type: 'Date'
          },
          {
              value:'updateBy',
              text: '更新人',
              type: 'string'
          },
          {
              value:'updateTime',
              text: '更新日期',
              type: 'Date'
          },
          {
              value:'remark',
              text: '备注',
              type: 'string'
          },
  ]

  export default {
    name: "MesMfProcessList",
    mixins:[JeecgListMixin],
    components: {
      JSuperQuery,
      FxCompontensModal,
      MesMfProcessModal,
       JDictSelectTag
    },
    data () {
      return {
        fieldList:superQueryFieldList,
        superQueryFlag:false,
        superQueryParams: '',
        description: '工序工单计划管理页面',
        cgButtonLinkList:[],
        title:'',//存表名
        EnhanceJS:'',
        cgButtonList:[],
        groupTag:[],
        queryInfo: [],
        code: '',
        // 表头
        columns: [
        ],
        //列设置
        settingColumns:[],
        //列定义
        defColumns: [
          {
            title: "序号",
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align: 'center',
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title: '线体',
            align: 'center',
            dataIndex: 'processType_dictText',
          },
          {
            title: '工站',
            align: 'center',
            dataIndex: 'taskSource',
          },
          {
            title: '排班人员',
            align: 'center',
            dataIndex: 'processbillno',
          },
          {
            title: '上岗人员',
            align: 'center',
            dataIndex: 'processTwocode',
          },
          {
            title: '匹配结果',
            align: 'center',
            dataIndex: 'processTwoname',
          },
          {
            title: '上岗时间',
            align: 'center',
            dataIndex: 'lineno',
          },
          {
            title: '迁出时间',
            align: 'center',
            dataIndex: 'linename',
          },
          {
            title: '操作',
            align: 'center',
            dataIndex: 'mcode',
          },
        ],
        url: {
          list: '/mes-manufacture/auto/mesMfProcess/list',
          delete: '/mes-manufacture/auto/mesMfProcess/delete',
          deleteBatch: '/mes-manufacture/auto/mesMfProcess/deleteBatch',
          exportXlsUrl: '/mes-manufacture/auto/mesMfProcess/exportXls',
          importExcelUrl: '/mes-manufacture/auto/mesMfProcess/importExcel',
          getColumns: '/mes-manufacture/online/cgform/api/getColumns/',
          buttonAction: '/mes-manufacture/online/cgform/api/doButton',
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${api.test}${this.url.importExcelUrl}`;
      },
     getWidth:function(){
       if(this.defColumns.length > 14){
         return {width : '500px'}
       }
     },
     tableScroll:function(){
         if(this.columns.length > 13){
             return { x: this.columns.length*150-450 }
         }
     }
    },    created() {
      this.initButtonList();
      this.initColumns();
      this.setdefColumns();
    },

methods: {
      setdefColumns(){
          if(this.columns.length > 13){
          let arrLength = this.columns.length-1
          this.columns.forEach((item,index)=>{
          item["width"] = 130
          })
          this.columns[arrLength]['fixed'] = 'right'
          this.columns[0]['fixed'] = 'left'
          this.columns[1]['fixed'] = 'left'
          }
      },
      initColumns(){
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name+":colsettings";
        let colSettings= Vue.ls.get(key);
        if(colSettings==null||colSettings==undefined){
          let allSettingColumns = [];
          this.defColumns.forEach(function (item,i,array ) {
            allSettingColumns.push(item.dataIndex);
          })
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        }else{
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter(item => {
            if(item.key =='rowIndex'|| item.dataIndex=='action'){
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          })
          this.columns =  cols;
        }
      },
      //列设置更改事件
      onColSettingsChange (checkedValues) {
        var key = this.$route.name+":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter(item => {
          if(item.key =='rowIndex'|| item.dataIndex=='action'){
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns =  cols;
      },

        //高级查询方法
        handleSuperQuery(arg) {
            if(!arg){
                this.superQueryParams=''
                this.superQueryFlag = false
            }else{
                this.superQueryFlag = true
                this.superQueryParams=JSON.stringify(arg)
            }
            this.loadData()
        },
        // 获取查询条件
        getQueryParams() {
            let sqp = {}
            if(this.superQueryParams){
                sqp['superQueryParams']=encodeURI(this.superQueryParams)
            }
            var param = Object.assign(sqp, this.queryParam, this.isorter);
            param.field = this.getQueryField();
            param.pageNo = this.ipagination.current;
            param.limit = this.ipagination.pageSize;
            return filterObj(param);
        },
      initDictConfig(){
      },

      // 弹出窗组件
      showDemoModal() {
        this.$refs.modalCompon.modalShow();
      },
      // 点击btn获取数据
      btnGetData(tableName,title){
        getAction(`${this.url.getColumns}`,{
          tableName:tableName
        }).then(
          res=>{
            if(res.code == 0){
              this.queryInfo = res.data.columns
              this.title = title
              this.dictOptions = res.data.dictOptions
              this.showDemoModal()
            }else{
               this.$message.warning(res.msg);
            }
          }
        )
      },

      //筛选分组
      getGroupTag(arrList) {
        let arr = [];
        var map = {},
            dest = [];
        arrList.forEach((item, index) => {
          if (item.groupTag) {
            arr.push(item);
          }
        });
        for (var i = 0; i < arr.length; i++) {
          var ai = arr[i];
          if (!map[ai.groupTag]) {
            dest.push({
              groupTag: ai.groupTag,
              name: ai.groupName,
              data: [ai]
            });
            map[ai.groupTag] = ai;
          } else {
            for (var j = 0; j < dest.length; j++) {
              var dj = dest[j];
              if (dj.groupTag == ai.groupTag) {
                dj.data.push(ai);
                break;
              }
            }
          }
        }
        this.groupTag = dest
        console.log(dest);
      },
      showLinkButton(item,record){
          let btn = new ButtonExpHandler(item.exp,record);
          return btn.show;
      },
        initButtonList(){
          getAction(`${this.url.getColumns}8ac49ec7733bce48017355583cbc011c`).then((res)=>{
            console.log("--获取自定义按钮->>",res);
            if(res.success){
              this.code = res.data.code;
              this.initCgButtonList(res.data.cgButtonList);
              this.initCgEnhanceJs(res.data.enhanceJs);
              this.getGroupTag(res.data.cgButtonList);
            }else{
              this.$message.warning(res.msg)
            }
          })
        },
        initCgEnhanceJs(enhanceJs){
          //console.log("--onlineList-js增强",enhanceJs)
          if(enhanceJs){
            let Obj = eval ("(" + enhanceJs + ")");
            this.EnhanceJS = new Obj(getAction,postAction,deleteAction);
            this.cgButtonJsHandler('created')
          }else{
            this.EnhanceJS = ''
          }
        },
        initCgButtonList(btnList){
          let linkArr = []
          let buttonArr = []
          if(btnList && btnList.length>0){
            for(let i=0;i<btnList.length;i++){
              let temp = btnList[i]
              if(temp.buttonStyle=='button'){
                buttonArr.push(temp)
              }else if(temp.buttonStyle=='link'){
                linkArr.push(temp)
              }
            }
          }
          this.cgButtonLinkList = [...linkArr]
          this.cgButtonList=[...buttonArr]
          console.log("链接增强", this.cgButtonLinkList);
        },
        cgButtonJsHandler(buttonCode){
          if(this.EnhanceJS[buttonCode]){
            this.EnhanceJS[buttonCode](this)
          }
        },
        cgButtonActionHandler(buttonCode){
          //处理自定义button的 需要配置该button自定义sql
          if(!this.selectedRowKeys || this.selectedRowKeys.length==0){
            this.$message.warning("请先选中一条记录")
            return false
          }
          if(this.selectedRowKeys.length>1){
            this.$message.warning("请只选中一条记录")
            return false
          }
          let params = {
            formId:this.code,
            buttonCode:buttonCode,
            dataId:this.selectedRowKeys[0]
          }
          console.log("自定义按钮请求后台参数：",params)
          postAction(this.url.buttonAction,params).then(res=>{
            if(res.success){
              this.loadData()
              this.$message.success("处理完成!")
            }else{
              this.$message.warning("处理失败!")
            }
          })

        },
        cgButtonLinkHandler(record,buttonCode,optType){
          if(optType=="js"){
            if(this.EnhanceJS[buttonCode]){
              this.EnhanceJS[buttonCode](this,record)
            }
          }else if(optType=="action"){
            let params = {
              formId:this.code,
              buttonCode:buttonCode,
              dataId:record.id
            }
            console.log("自定义按钮link请求后台参数：",params)
            postAction(this.url.buttonAction,params).then(res=>{
              if(res.success){
                this.loadData()
                this.$message.success("处理完成!")
              }else{
                this.$message.warning("处理失败!")
              }
            })
          }
        },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';

  .BtMargin{
    margin-right:10px;
  }
  .sprint i{  
    margin-left: 20px;
  }

  .switch{
      margin-left:10px;
  }
  .putBoxShad:hover{
    box-shadow:-1px 0px 20px #333333;
    margin-bottom:10px;
}
.ant-empty-normal{
  margin:0
}
.left_container_laber{
  display: flex;
  justify-content:space-between;
  padding:10px 20px 10px 10px;
}
.left_container_info{
  display:flex;
  justify-content:space-between;
  padding:10px;
}
.container{
  height:100%;
  display:flex;
  margin-top:20px;
}
.left{
   height:500px;
   width:300px;
   border:solid 1px #eee;
   display: flex;
   flex-direction:column;
}
.right{
   height:500px;
  flex-grow: 1;
  border:solid 1px #eee;
  margin-left:20px;
}


.rightContainer_top,
.rightContainer_bottom{
  display:flex;
  justify-content:space-evenly;
  margin-top:50px;
}
.container_1,
.container_2,
.container_3{
  border:1px solid #eee;
  height:100%;
  width:150px;
  flex-direction:column;
}
.container1_2{
  display:flex;
}
.container1_2_1,
.container1_2_2{
  flex-grow:1;
  height:50px;
  line-height:50px;
  padding-left:10px;
}
.container1_2_3,
.container1_2_4,
.container1_2_5{
  /* border:solid 1px; */
   padding-left:10px;
   margin:10px auto;
}
.setPage{
  display:flex;
  justify-content:center;
  margin-top:50px;
}
  
</style>
